package com.oa.util;

import java.util.List;

public class PageUtil<T> {

	//当前页
	private int currentPage=1;
	//每页数据条数
	private int pageSize=4;
	//总的数据条数
	private int totalCount;
	//当前取得的数据内容
	private List<T> data;
	
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public List<T> getData() {
		return data;
	}
	public void setData(List<T> data) {
		this.data = data;
	}
	public PageUtil(int currentPage, int pageSize, int totalCount, List<T> data) {
		super();
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.data = data;
	}
	public PageUtil() {
		super();
	}

	//获取开始的数据(获取需要排除的数据条数)
	public int getBegin() {
		return (this.currentPage-1)*this.pageSize;
	}
	//select * from  limit 开始位置，每页数据条数
	//获取总页码
	public int getTotalPage() {
		return (int)Math.ceil(this.getTotalCount()*1.0/this.getPageSize());
	}
	
	//获取当前页码内容(这里特指分页条)
	public String getPageList() {
		StringBuffer sBuffer=new StringBuffer();
		//拼头部
		sBuffer.append("<nav aria-label='...'><ul class='pagination'>");
		//拼上一页
		sBuffer.append("<li><a href='#' onClick='prePage()'>&laquo;</a></li>");
		//循环拼中间页码
		for (int i = 1; i <= this.getTotalPage(); i++) {
			if (i==currentPage) {
				sBuffer.append("<li class='active'><a href='#'>"+i+"</a></li>");				
			}else {
				sBuffer.append("<li><a href='#' onClick='changePage(this)'>"+i+"</a></li>");				

			}
		}
		//拼下一页
		sBuffer.append("<li><a href='#' onClick='nextPage()'>&raquo;</a></li>");
		//拼尾部
		sBuffer.append("</ul></nav>");
		return sBuffer.toString();
	}
}
